
//需要修改
var base_host_jono = "fpapi.jingkao.cc";//后端域名


window.JONO_HOST = "http://"+base_host_jono;
window.JONO_KEFUWS= "ws://fpwsi.jingkao.cc";
window.LOCAL_HOST = "http://" + window.location.host;
window.LOCAL_DOMAIN = window.location.host;
window.SHORT_URL = JONO_HOST + "/url/short_url";
//公共方法
var JONO_TOOL = {
    createXHR: function () {
        var XHR = [
            function () {
                return new XMLHttpRequest()
            },
            function () {
                return new ActiveXObject("Msxml2.XMLHTTP")
            },
            function () {
                return new ActiveXObject("Msxml3.XMLHTTP")
            },
            function () {
                return new ActiveXObject("Microsoft.XMLHTTP")
            }
        ];
        var xhr = null;
        for (var i = 0; i < XHR.length; i++) {
            try {
                xhr = XHR[i]();
            } catch (e) {
                continue
            }
            break;
        }
        return xhr;
    },
    get: function(url){
        var xhr = this.createXHR();
        xhr.open("GET", url, false);
        xhr.setRequestHeader('Authorization', this.get_token());
        xhr.withCredentials = true;
        xhr.send(null);
        return JSON.parse(xhr.responseText);
    },
    get_token: function(){
       var FPHDSdkUserInfo =  window.localStorage.getItem("FPHDSdkUserInfo")
       if(FPHDSdkUserInfo){
        var FPHDSdkUserInfos = FPHDSdkUserInfo.split("||");
        return FPHDSdkUserInfos[3]?FPHDSdkUserInfos[3]:null;
       }
       return null
    },
    isWeiXin: function () {
        var ua = window.navigator.userAgent.toLowerCase();
        if (ua.match(/MicroMessenger/i) == 'micromessenger') {
            return true;
        } else {
            return false;
        }
    },
    getUrlParam:function(name){
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) return unescape(r[2]);
        return null;
    }
}

function validateLogin(){
    let res = JONO_TOOL.get(JONO_HOST + "/index/api/validateLogin");
    if(res.code == 1){
        return res.data;
    }else{
        console.log("123")
        // if(JONO_TOOL.isWeiXin()){
        //     var return_url = window.location.href;
        //     localStorage.setItem("return_url",return_url);
        //     window.location.href = '/login.html';
        // }
        // return null;
        window.location.href = '/';
    }
}